#include <memory>
#include <string>
#include "XnccServer.h"
#include "XnccType.h"
#include "flat_hash_map"
namespace xncc {
namespace foundation {
    class EventLoop;
    class DatagramSocketChannel;
    class SubDatagramServer
    {
      public:
        explicit SubDatagramServer(EventLoop* loop);
        ~SubDatagramServer();
        SubDatagramServer(const SubDatagramServer&)             = delete;
        SubDatagramServer(const SubDatagramServer&&)            = delete;
        SubDatagramServer& operator=(const SubDatagramServer&)  = delete;
        SubDatagramServer& operator=(const SubDatagramServer&&) = delete;

        void acceptNewConnection(int sockfd, types::connection_id_t connId, std::shared_ptr<XnccAddress> peerAddr);

      private:
        void handleIoMsg(const char* msg, uint32_t len, types::thread_id_t tid, types::connection_id_t connId);

        void newConnection(int sockfd, types::connection_id_t connId, std::shared_ptr<XnccAddress> peerAddr);
        void removeConnection(types::connection_id_t connId, const std::string& disconnectedReason);

        EventLoop*                                                                         loop_;  // the acceptor loop
        ska::flat_hash_map<types::connection_id_t, std::shared_ptr<DatagramSocketChannel>> clientChs_;
    };
}  // namespace foundation
}  // namespace xncc